package com.tangsm.spring.boot.event.publisher.listener.listener;

import com.tangsm.spring.boot.event.publisher.listener.event.UserRegisterEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 事件监听者
 *
 * <p>通过@EventListener注解注册事件监听者</p>
 *
 * @author tangsm
 */
@Component
public class UserCommonListener {
    private static final Logger log = LoggerFactory.getLogger(UserCommonListener.class);

    /**
     * 注册处理应用程序事件（事件监听者）
     *
     * @param event 事件
     */
    @EventListener
    public void onUserRegisterEvent(UserRegisterEvent event) {
        log.info("事件发布者：{}", event.getSource().toString());
        //发邮件
        log.info("UserCommonListener，正在发送邮件至：{}", event.getUser().getEmail());
        //发短信
        log.info("UserCommonListener，正在发短信到：{}", event.getUser().getPhoneNum());
    }
}
